package ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.presentation.controller.user.devicedata;

import java.util.ArrayList;
import java.util.List;

import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.service.SimpleCommandService;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.devicecontroller.command.Command;

/**
 * 
 * Este Bean es utilizado en las vistas
 * simpleuser/devicedata.xhtml
 */

public class SimpleCommandBean {

	private SimpleCommandService commandServ;
	
	public SimpleCommandBean(SimpleCommandService al) {
		commandServ = al;
	}
	public String getName(){
		return commandServ.getName();
		
	}
	public void on(){
		commandServ.setOn();
	}
	public void off(){
		commandServ.setOff();		
	}
	public String getState(){
		int state = commandServ.getState();
		switch(state){
		    case Command.DONE:
		    	return "devicedata.command.state.done";
		    case Command.FAIL:
		    	return "devicedata.command.state.fail";
		    case Command.NOT_EXECUTING:
		    	return "devicedata.command.state.notexecuting";
		    case Command.PROCESSING:
		    	return "devicedata.command.state.processing";
		    case Command.WAITING:
		    	return "devicedata.command.state.waiting";
		}
		return null;
	}
	
	public boolean isDisabledbtn(){
		int state = commandServ.getState();
		return state == Command.WAITING || state == Command.PROCESSING ;
	}
	
	public static List<SimpleCommandBean> wrap(
			List<SimpleCommandService> simpleCommandsService) {
		ArrayList<SimpleCommandBean> ret = new ArrayList<SimpleCommandBean>();
		for(SimpleCommandService al: simpleCommandsService){
			ret.add(new SimpleCommandBean(al));
		}
		return ret;
	}
	
}
